package com.sfh.service.model;

import java.util.Date;

import com.sfh.service.model.table.UserTable;
import com.sfh.service.util.SQLHelp;

public class UserModel extends BaseModel<UserModel> {

	private static final long serialVersionUID = -1623740322634215635L;
	public static final UserModel USER = new UserModel().dao();

	@Override
	public UserModel findById(Object idValue) {
		return super.findFirst("select * from " + UserTable.Table + " where " + UserTable.id + "=?", idValue);
	}

	public UserModel getUserModel(SQLHelp sql) {
		return USER.findFirst(sql.build());
	}

	public long getId() {
		return this.get(UserTable.id.toString());
	}

	public void setId(long userId) {
		this.set(UserTable.id.toString(), userId);
	}

	public String getName() {
		return this.get(UserTable.name.toString());
	}

	public void setNike(String userName) {
		this.set(UserTable.nike.toString(), userName);
	}
	public String getNike() {
		return this.get(UserTable.nike.toString());
	}

	public void setName(String userName) {
		this.set(UserTable.name.toString(), userName);
	}

	public int getSex() {
		return this.get(UserTable.sex.toString());
	}

	public void setSex(int userSex) {
		this.set(UserTable.sex.toString(), userSex);
	}

	public String getAddress() {
		return this.get(UserTable.address.toString());
	}

	public void setAddress(String userAddress) {
		this.set(UserTable.address.toString(), userAddress);
	}

	public long getWealth() {
		return this.getLong(UserTable.wealth.toString());
	}

	public void setWealth(long userWealth) {
		this.set(UserTable.wealth.toString(), userWealth);
	}

	public long getCharm() {
		return this.getLong(UserTable.charm.toString());
	}

	public void setCharm(long userCharm) {
		this.set(UserTable.charm.toString(), userCharm);
	}

	public String getUrl() {
		return this.get(UserTable.url.toString());
	}

	public void setUrl(String userUrl) {
		this.set(UserTable.url.toString(), userUrl);
	}

	public long getVerion() {
		return this.getLong(UserTable.version.toString());
	}

	public void setVerion(long verion) {
		this.set(UserTable.version.toString(), verion);
	}

	public Date getVipTime() {
		return this.get(UserTable.vipTime.toString());
	}

	public void setVipTime(Date time) {
		this.set(UserTable.vipTime.toString(), time);
	}

	public void setPassWord(String pwd) {
		this.set(UserTable.pwd.toString(), pwd);
	}

	/***
	 * 
	 * @param name
	 * @return
	 */
	@Deprecated
	public boolean isExit(String name) {
		SQLHelp sql = new SQLHelp(UserTable.Table);
		sql.addWhereEqualTo(UserTable.name, name);
		return USER.findFirst(sql.build()) != null;
	}

	/***
	 * 判断特权是否可以使用
	 * 
	 * @return true 可以
	 */
	public boolean isVip() {
		Date time = this.getVipTime();
		if (time == null) {
			return false;
		}

		Date now = new Date();
		return now.before(time);
	}
}
